/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.sensor.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import nl.cloudfarming.sensor.ParsedUnit;

/**
 * @author Merijn Zengers
 */

@Entity
@Table(name = "PLOT")
public class PlotBO implements Serializable, ParsedUnit {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="PLOT_ID")
    private long plotId;
    
    @Column(name="NAME")
    private String name;

    @Column(name="WKT" ,length=10000)
    private String WKT;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name = "plotDataFileId")
    private PlotDataFileBO plotDataSensorFile;

     /**
     * For JPA use only.
     */
    @Deprecated
    protected PlotBO() {
    }

    public PlotBO(PlotDataFileBO plotDataFileBO, String name, String WKT) {
        this.plotDataSensorFile = plotDataFileBO;
        this.name = name;
        this.WKT = WKT;
    }

    public long getPlotId(){
        return plotId;
    }

    public String getWKT() {
        return WKT;
    }

    public void setWKT(String WKT) {
        this.WKT = WKT;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public PlotDataFileBO getPlotDataFileBO(){
        return this.plotDataSensorFile;
    }

    public void setPlotDataFileBO(PlotDataFileBO plotDataFileBO){
        this.plotDataSensorFile = plotDataFileBO;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PlotBO other = (PlotBO) obj;
        if ((this.WKT == null) ? (other.WKT != null) : !this.WKT.equals(other.WKT)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 19 * hash + (this.WKT != null ? this.WKT.hashCode() : 0);
        return hash;
    }

}
